#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import gtk
from ConfigParser import SafeConfigParser
import app

class Config(SafeConfigParser):
    def read(self):
        read = SafeConfigParser.read(self, 
            [os.path.join(app.data_dir, "default.config"), app.config_file])
        app.debug("Read: %s"%' '.join(read), "config")
    
    def write(self):
        fd = open(app.config_file, 'w')
        SafeConfigParser.write(self, fd)
        app.debug("Configuration written", "config")
        del fd


class PreferencesWindow:
    def __init__(self, appinst):
        self.appinst = appinst
        self.config = appinst.config
        
        wTree = gtk.glade.XML(app.glade_file, "preferences_window")
        self.wTree = wTree
        self.window = wTree.get_widget("preferences_window")
        
        _signals = {
            "button_close_clicked": 
                lambda w: self.appinst.close_window(self),
            "destroy":
                lambda w: self.appinst.close_window(self),
        }
        wTree.signal_autoconnect(_signals)
        
        self.load_config()
        self.window.show_all()
        
    def close(self):
        self.window.destroy()
    
    def load_config(self):
        """Fill in the preferences dialog."""

